import java.util.*;


public class Solution {
    /**
     * 
     * @param prices int整型一维数组 
     * @return int整型
     */
    public int maxProfit (int[] prices) {
        // write code here
        if (prices.length < 2)
            return 0;
        
        int buy = prices[0];
        int sell = 0;
        for (int i = 1; i < prices.length; i++) {
            if (prices[i] > buy)    
                sell = Math.max(sell, prices[i] - buy);
            else 
                buy = prices[i];
        }
        return sell;

    }
}